﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Reactive.Linq;
using System.Reactive;

using YLServerInterface.UserControls;

namespace movingControl
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            ug.Children.Remove(bh);
            ug.Children.Insert((Int32.Parse(bh.Tag.ToString()) - 1), bh);
            //ug.Rows = 1;
            //bh.Content = "1";
            //List<UIElement> items = new List<UIElement>();

            //foreach (UIElement item in ug.Children)
            //{
            //    items.Add(item);
            //}
            //ug.Children.Clear();

            //items.Sort(new Comparison<UIElement>((a, b) =>
            //        string.Compare((a as Button).Content.ToString(), (b as Button).Content.ToString())
            //    ));
            //foreach (var item in items)
            //{
            //    ug.Children.Add(item);
            //}
        }
        ImageCutter cutter;
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            cutter = new ImageCutter(@"F:\YL\2013-04-30\泰安资料\IMG_7695.jpg", @"F:\YL\2013-04-30\泰安资料\123.jpg", 400, 586);
            ug.Children.Add(cutter);

        }

        private void Button_KeyDown(object sender, KeyEventArgs e)
        {


        }

        private void Button_MouseDown(object sender, MouseButtonEventArgs e)
        {


        }
        void moveLeft(Button b)
        {
            var now = int.Parse(b.Tag.ToString());
            ug.Children.Remove(b);
            ug.Children.Insert(now - 1, b);
            b.Tag = (now - 1).ToString();
        }

        private void bg_Click(object sender, RoutedEventArgs e)
        {
            cutter.Cut();
        }

        private void bh_MouseDown(object sender, MouseButtonEventArgs e)
        {
            var startP = e.GetPosition(sender as IInputElement);
            var ctrolDown = Observable.FromEventPattern<KeyEventArgs>(bg, "KeyDown").Where(
                          ep => ep.EventArgs.Key == Key.LeftCtrl);
            var mDown = Observable.FromEventPattern<MouseEventArgs>(bg, "MouseDown");
            var mMove = Observable.FromEventPattern<MouseEventArgs>(bg, "MouseMove");
            var mDownMove = mMove.SkipUntil(mDown);


        }
    }
}
